
options(scipen = 999)  # turns off scientific notations like 1e+40

rm(list=ls(all=TRUE))

#Plot 1: Apprehensions (adjusted for asylum apprehensions) for El Paso, San Diego, and Tucson sectors. 
#Plot demonstrates changes in apprehensions before and after Operations Gatekeeper and Hold-the-Line. 

library(foreign)
library(lattice)
library(gridExtra)
library(ggplot2)
library(grid)
library(ggthemes)

#Set wd to your own computer
#setwd("~/Dropbox/Border Perceptions/GMC Immigration Fact")
 
  
threesectors<-read.csv("GMC1_appsfor3sectors.csv", header=TRUE)

attach(threesectors)

Year<-factor(Year)

#Basic plot
ggplot(threesectors, aes(Year, Adjusted.Apprehensions, color=Sector_name)) +
  geom_line()

#Improved plot
threeS<-ggplot(threesectors, aes(Year, Adjusted.Apprehensions, color=Sector_name)) +
  geom_line(size = .8, alpha = .8) +
  #geom_line(size=.8, alpha =.8, aes(linetype = Sector_name, col = Sector_name)) +
  geom_point(position = position_dodge(width = 0.0), size=2, aes(shape=Sector_name)) +
  ggtitle("Migrant apprehensions in El Paso, San Diego, and Tucson sectors",
          subtitle = "FY 1989-2019 (adjusted for FUA and UCA data)") +
  labs(x = "Year", y = "Adjusted migrant apprehensions") +
theme_bw() +  
  theme(legend.justification=c(.98,.98),
        legend.position=c(.98,.98),
        legend.key.size = unit(.5, "cm"),
        legend.text = element_text(size=8),
        legend.title=element_text(size=8),
        axis.text.y = element_text(size=6),
        axis.text.x = element_text(size=6),
        axis.title.y=element_text(size=8),
        axis.title.x=element_text(size=8),
        plot.title = element_text(size=8), 
        plot.subtitle = element_text(size=8), 
        panel.grid.major = element_line(), 
        panel.grid.minor = element_line(),
        panel.background = element_blank(), 
        axis.line = element_line(colour = "black"))   
  #scale_fill_brewer(palette = "Dark2"))  # Color palette
threeS<-threeS + scale_color_manual(values = c("orange", "blue", "black"))
threeS<-threeS + geom_vline(xintercept=1993, linetype="dashed", 
                       color = "grey70", size=.5)
threeS<-threeS + geom_vline(xintercept=1994, linetype="dashed", 
                            color = "grey70", size=.5)
threeS


#Plot 2: Indicators of Enforcement in Tucson sector: USBP Agents, Adj. apprehensions, Recovered remains


tucsonsector<-read.csv("GMC2_Tucsonsector.csv", header=TRUE)

attach(tucsonsector)

#Basic plot
ggplot(tucsonsector, aes(Year, amount, color=Indicator)) +
  geom_line()

#Improved plot
tuxon<-ggplot(tucsonsector, aes(Year, amount, color=Indicator)) +
  geom_line(size = .8, alpha = .8) +
  geom_point(position = position_dodge(width = 0.0), size=2, aes(shape=Indicator)) +
  ggtitle("Apprehensions, USBP agents and migrant deaths in Tucson Sector",
          subtitle = "2000-2019") +
  labs(x = "Year", y = "Amount") +
  theme_bw() +  
  theme(legend.justification=c(.98,.98),
        legend.position=c(.98,.98),
        legend.key.size = unit(.5, "cm"),
        legend.text = element_text(size=8),
        legend.title=element_text(size=8),
        axis.text.y = element_text(size=6),
        axis.text.x = element_text(size=6),
        axis.title.y=element_text(size=8),
        axis.title.x=element_text(size=8),
        plot.title = element_text(size=8), 
        plot.subtitle = element_text(size=8), 
        panel.grid.major = element_line(), 
        panel.grid.minor = element_line(),
        panel.background = element_blank(), 
        axis.line = element_line(colour = "black"))   
#scale_fill_brewer(palette = "Dark2"))  # Color palette
tuxon<-tuxon + scale_color_manual(values = c("orange", "blue", "black"))

tuxon

#Plot 3: Recovery rate=Number of remains recovered/Apprehensions in 10ks


rate<-read.csv("GMC3_recoveryrate.csv", header=TRUE)

attach(rate)

#Basic plot
ggplot(rate, aes(Year, Recovery, color=Indicator)) +
  geom_line()

#Improved plot
remains<-ggplot(rate, aes(Year, Recovery, color=Indicator)) +
  geom_line(size = .8, alpha = .8) +
  geom_point(position = position_dodge(width = 0.0), size=2, aes(shape=Indicator)) +
  ggtitle("Recovered remains and estimated recovery rate per migrant apprehensions",
          subtitle = "2000-2019") +
  labs(x = "Year", y = "Amount") +
  theme_bw() +  
  theme(legend.justification=c(.02,.98),
        legend.position=c(.02,.98),
        legend.key.size = unit(.5, "cm"),
        legend.text = element_text(size=8),
        legend.title=element_text(size=8),
        axis.text.y = element_text(size=6),
        axis.text.x = element_text(size=6),
        axis.title.y=element_text(size=8),
        axis.title.x=element_text(size=8),
        plot.title = element_text(size=8), 
        plot.subtitle = element_text(size=8), 
        panel.grid.major = element_line(), 
        panel.grid.minor = element_line(),
        panel.background = element_blank(), 
        axis.line = element_line(colour = "black"))   
#scale_fill_brewer(palette = "Dark2"))  # Color palette
remains<-remains + scale_color_manual(values = c("orange", "blue"))

remains

#Western Shift: Plot 4.  GMC

westshift<-read.csv("GMC4_westernshift.csv", header=TRUE)

attach(westshift)



upper=pr1 + qnorm(.975)*se
lower=pr1 + qnorm(.025)*se
Probability<-pr1
Year<-factor(Group)

west<-cbind(westshift, upper, lower, Probability, Year)

westward<-ggplot(data = west, aes(x = Year, y = Probability, ymin = lower, ymax = upper, group=1)) +
  geom_line(size = .8, alpha = .8, color="blue") +
  geom_point(position = position_dodge(width = 0.0), size=.8, color="blue") +
  geom_errorbar(position = position_dodge(width = 0.0), width = 0.2, color="blue")  +
  #coord_flip() + 
  ylim(0, .6) + 
  ggtitle("Recovered remains in western Arizona significantly increased over time",
          subtitle = "(Probability estimates of location of remains recovery, 2001-2020)") +
  labs(x = "Year", y = "Probability of recovery in western AZ desert") +
  theme_bw() +
  theme(legend.justification=c(.98,.98),
        legend.position=c(.98,.98),
        legend.key.size = unit(.5, "cm"),
        legend.text = element_text(size=8),
        legend.title=element_text(size=8),
        axis.text.y = element_text(size=6),
        axis.text.x = element_text(size=6),
        axis.title.y=element_text(size=8),
        axis.title.x=element_text(size=8),
        plot.title = element_text(size=8), 
        plot.subtitle = element_text(size=8), 
        panel.grid.major = element_line(), 
        panel.grid.minor = element_line(),
        panel.background = element_blank(), 
        axis.line = element_line(colour = "black"))   

westward

gmcGRID<-grid.arrange(threeS, tuxon, remains, westward, ncol=2, nrow=2, 
         top="Figure 1. Implications of prevention-by-deterrence on migrant deaths in the Tucson Sector")




